import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.ListItem;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import com.lowagie.text.DocumentException;


import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 使用itext 生成Pdf
 */
public class PDFConvertDemo {

    public static void main(String[] args) throws IOException, DocumentException, com.itextpdf.text.DocumentException {
        /**
         * 生成文件的路径
         */
        final String path ="/Users/wuxinbo/pdfdemo/hello-world.pdf";
        final String imagepath ="/Users/wuxinbo/pdfdemo/test.png";
//        final String htmlPath="/Users/wuxinbo/pdfdemo/start.html";
        Image image = new Image(ImageDataFactory.create(imagepath));
        Document document =new Document(PageSize.A4);
        PdfWriter.getInstance(document,new FileOutputStream(path));
        document.open();
        BaseFont font =BaseFont.createFont("/Users/wuxinbo/fonts/SIMSUN.TTC,0",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
        Font font1 =new Font(font);
        document.add(new Paragraph("你好hihi",font1));
        List list =new List();
        list.add(new ListItem("今天是个好日子hello"));
        document.addTitle("这是title");
//        document.add(image);
        document.close();
    }
}
